package com.ultrawise.survey.core.base;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.ultrawise.survey.common.utils.DateEditor;

/**
 * action 基类
 */
public class BaseContoller extends SimpleFormController
{
	public static final String COMMON_FAIL_PAGE = "fail";
	public static final String COMMON_FAIL_ALERT_KEY = "fail_key";
	public static final String USER_SESSION_KEY = "_user_session_key_";

	public static final String JSON_CONTENT_VIEW = "common/outJson";

	// 直接访问jsp
	@RequestMapping("/{jsp}.htm")
	public String jsp(@PathVariable(value = "jsp") String jsp)
	{
		LogInfo.logger.info(jsp);
		return jsp;
	}

	@InitBinder
	protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception
	{
		DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		//binder.registerCustomEditor(Date.class, new DateEditor(fmt, true));
		binder.registerCustomEditor(Integer.class, new CustomNumberEditor(Integer.class, true));
		//setRequest(request);
		// System.out.println("=======================绑定类::" + request);
		super.initBinder(request, binder);
	}


}
